Ext.define('myTreePicker',{
    extend: 'Ext.ux.TreePicker',
    config: {
        /**
		 * @cfg {Ext.data.TreeStore} store A tree store that the tree picker
		 *      will be bound to
		 */
        store: null,

        /**
		 * @cfg {String} displayField The field inside the model that will be
		 *      used as the node's text. Defaults to the default value of
		 *      {@link Ext.tree.Panel}'s `displayField` configuration.
		 */
        displayField: null,

        /**
		 * @cfg {Array} columns An optional array of columns for multi-column
		 *      trees
		 */
        columns: null,

        /**
		 * @cfg {Boolean} selectOnTab Whether the Tab key should select the
		 *      currently highlighted item. Defaults to `true`.
		 */
        selectOnTab: true,

        /**
		 * @cfg {Number} maxPickerHeight The maximum height of the tree
		 *      dropdown. Defaults to 300.
		 */
        maxPickerHeight: 300,

        /**
		 * @cfg {Number} minPickerHeight The minimum height of the tree
		 *      dropdown. Defaults to 100.
		 */
        minPickerHeight: 100,
        
        rootVisible: false,// 是否显示根节点
        
        useArrows: true,// 是否用箭头
    },
    /**
	 * Creates and returns the tree panel to be used as this field's picker.
	 */
    createPicker: function() {
    	console.log(this);
        var me = this,
            picker = new Ext.tree.Panel({
                baseCls: Ext.baseCSSPrefix + 'boundlist',
                shrinkWrapDock: 2,
                store: me.store,
                floating: true,
                rootVisible: me.rootVisible,
                useArrows: me.useArrows,
                displayField: me.displayField,
                columns: me.columns,
                minHeight: me.minPickerHeight,
                maxHeight: me.maxPickerHeight,
                manageHeight: false,
                shadow: false,
                childrenUrl:me.childrenUrl,
                listeners: {
                    scope: me,
                    itemclick: me.onItemClick,
                    itemkeydown: me.onPickerKeyDown,
                    beforeitemexpand:me.getChildren
                }
            }),
            view = picker.getView();

        if (Ext.isIE9 && Ext.isStrict) {
            // In IE9 strict mode, the tree view grows by the height of the
			// horizontal scroll bar when the items are highlighted or
			// unhighlighted.
            // Also when items are collapsed or expanded the height of the view
			// is off. Forcing a repaint fixes the problem.
            view.on({
                scope: me,
                highlightitem: me.repaintPickerView,
                unhighlightitem: me.repaintPickerView,
                afteritemexpand: me.repaintPickerView,
                afteritemcollapse: me.repaintPickerView
            });
        }
        return picker;
    },
    //获取孩子节点
    getChildren: function(record, eOpts) {
    	var childrenUrl=this.childrenUrl;
    	if(record.data.id!='root'){
			if (record.get('isHas') == 0) {
		        var id = record.get('id');
		        Ext.Ajax.request({
		        	url:childrenUrl+id,
		            //url:zuulUrl + '/' + testServiceName + '/common/testDesign/childrenIsSubject/' + id,
		            method: 'get',
		            async: false, // ASYNC 是否异步( TRUE 异步 ,
									// FALSE 同步)
		            success: function (response, opts) {
		                var obj = Ext.decode(response.responseText);
		                Ext.each(obj, function (node) {// 获得数据之后先将title的值赋值给text
		                    if(node.childrenCount==0)// 如果是测试计划的模式并且这个节点的可显示节点数量等于0则将此文件夹设置为不可展开
		                    	node.expandable=false;
		                });
		                record.appendChild(obj);
		                record.set("isHas", 1);
		            },
		            failure: function (response, opts) {
		            	var obj = Ext.decode(response.responseText);
		            	if(obj.code==401||obj.code==402||obj.code==403)
		            		Ext.Msg.alert("Error", obj.message);
		            	else
		            		Ext.Msg.alert("Error", "该功能暂时不可用！");
		            }
		        });
		     }
		}
    }
});

//用于给测试需求转测试计划选择目标主题文件夹的treePicker
var chooserDesignSbjectTreePicker=Ext.create('myTreePicker',{
	fieldLabel: '主题',
    labelWidth: 50,
	itemId: 'testReqToDesignTreePicker',
	editable: false,
	queryMode: 'remote',
	emptyText: '--请选择--',
	rootVisible: false,
    useArrows: true,// 是否用箭头
	store: chooseTestDesignStore,
	displayField: 'title',
	valueField: 'id',
	forceSelection: true,
	scrollable: true,
	minPickerHeight: 200,
	value: '', // 这个定义很重要，如果没有设置
	childrenUrl:zuulUrl + '/' + testServiceName + '/common/testDesign/childrenIsSubject/'
});